package com.eascs.dubbo.api.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.admin.api.loanapply.LoanAfterArchiveService;
import com.eascs.admin.o2o.compensatory.entity.CompensatoryDataEnter;
import com.eascs.admin.o2o.compensatory.service.O2oDCLoanService;
import com.eascs.app.dao.PageResult;
import com.eascs.archive.entity.ArchiveBorrowEntity;
import com.eascs.archive.entity.ArchiveRecordEntity;
import com.eascs.archive.entity.FieldEntity;
import com.eascs.archive.service.ArchiveBorrowService;
import com.eascs.archive.service.ArchiveRecordService;
import com.eascs.archive.service.ArchiveService;

@Service
public class LoanAfterArchiveServiceImpl implements LoanAfterArchiveService {

	@Autowired
	ArchiveBorrowService archiveBorrowService;

	@Autowired
	ArchiveService archiveService;

	@Autowired
	ArchiveRecordService archiveRecordService;

	@Autowired
	O2oDCLoanService o2oDCLoanService;

	/**
	 * 借阅记录
	 * 
	 * @param entity
	 * @return
	 */
	@Override
	public PageResult<Object[]> getBorrowRecord(ArchiveBorrowEntity archiveBorrowEntity) {
		return archiveBorrowService.queryListPage(archiveBorrowEntity, Integer.MAX_VALUE, 0).getModel();
	}

	/**
	 * 银行归档、财务行归档、存柜资料（贷后归档详情）
	 * 
	 * @param bankTypeId
	 * @param formTypeId
	 * @return
	 */
	@Override
	public List<FieldEntity> getFieldListByType(String bankTypeId, String formTypeId) {
		return archiveService.getFieldListByType(bankTypeId, formTypeId);
	}

	/**
	 * 代偿信息（贷后归档详情）
	 * 
	 * @param bid
	 * @return
	 */
	@Override
	public ArchiveBorrowEntity getArchiveBorrowById(String bid) {
		return archiveBorrowService.queryArchiveBorrowById(bid);
	}

	/**
	 * 存柜资料-档案柜号编号（贷后归档详情）
	 * 
	 * @param loanapplyNo
	 * @param bankType
	 * @param formType
	 * @return
	 */
	@Override
	public ArchiveRecordEntity getArchiveRecord(String loanapplyNo, String bankType, String formType) {
		return archiveRecordService.queryArchiveRecord(loanapplyNo, bankType, formType).getModel();
	}

	/**
	 * 代偿信息（贷后归档详情）2
	 * 
	 * @param bid
	 * @return
	 */
	@Override
	public ArchiveBorrowEntity getArchiveBorrowByEntity(String billCode) {
		CompensatoryDataEnter compensatory = o2oDCLoanService.findByBillCode(billCode);
		ArchiveBorrowEntity archiveBorrowEntity = new ArchiveBorrowEntity();
		if (compensatory != null) {
			archiveBorrowEntity.setDc_trans_ck(compensatory.getTransferInvitationNum());
			archiveBorrowEntity.setDc_trans_sy(compensatory.getTransferInvitationResidueNum());
			archiveBorrowEntity.setDc_trans_jy(compensatory.getTransferInvitationLoanNum());

			archiveBorrowEntity.setDc_ems_ck(compensatory.getEnsBillNum());
			archiveBorrowEntity.setDc_ems_sy(compensatory.getEnsBillResidueNum());
			archiveBorrowEntity.setDc_ems_jy(compensatory.getEnsBillLoanNum());

			archiveBorrowEntity.setDc_receipt_ck(compensatory.getReceiptNum());
			archiveBorrowEntity.setDc_receipt_sy(compensatory.getReceiptResidueNum());
			archiveBorrowEntity.setDc_receipt_jy(compensatory.getReceiptLoanNum());

			archiveBorrowEntity.setDc_refund_ck(compensatory.getRefundDetailNum());
			archiveBorrowEntity.setDc_refund_sy(compensatory.getRefundDetailResidueNum());
			archiveBorrowEntity.setDc_refund_jy(compensatory.getRefundDetailLoanNum());
		}
		return archiveBorrowEntity;
	}

}
